import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains


class TestCase:
    def __init__(self):
        self.driver = webdriver.Chrome()
        self.driver.get('https://sahitest.com/demo/clicks.htm')
        self.ac = ActionChains(self.driver)

    def click(self):  # 点击
        click_me = self.driver.find_element_by_xpath('//input[@value="click me"]')
        self.ac.click(click_me).perform()

    def double(self):
        double = self.driver.find_element_by_xpath('//input[@value="dbl click me"]')
        self.ac.double_click(double).perform()
        self.ac.click(double).perform()
        self.ac.click(double).perform()

    def context_click(self):
        right_click = self.driver.find_element_by_xpath('//input[@value="right click me"]')
        self.ac.context_click(right_click).perform()

    def drag_and_drop(self):
        self.driver.get('https://sahitest.com/demo/dragDropMooTools.htm')
        drag = self.driver.find_element_by_id('dragger')
        drop = self.driver.find_element_by_xpath('//div[3]')
        self.ac.drag_and_drop(drag, drop).perform()
    def move_to_element(self):
        self.driver.get('https://sahitest.com/demo/mouseover.htm')
        move = self.driver.find_element_by_xpath('//input[@value="Write on hover"]')
        self.ac.move_to_element(move).perform()

    def quit(self):
        time.sleep(3)
        self.driver.quit()


if __name__ == '__main__':
    case = TestCase()
    # case.click()
    # case.double()
    # case.context_click()
    # case.drag_and_drop()
    case.move_to_element()
    case.quit()
